
/**
 * 最长回文
 *
 * */

var longestPalindrome = function(s) {
    var slength = s.length;
    var longest = '';
    var start = 0;
    var end = 1;

    //奇数回文
    for(var i = 0; i < slength; i++)
    {
        var j = i-1, k = i+1;
        while(j>=0 && k<slength && s[j] == s[k])
        {

            if(k+1-j > end)
            {
                start = j;
                end = k+1-j;
            }
            j--;
            k++;
        }
    }

    //偶数回文
    for(var i = 0; i < slength; i++)
    {
        var j = i, k = i+1;
        while(j>=0 && k<slength && s[j] == s[k])
        {

            if(k+1-j > end)
            {
                start = j;
                end = k+1-j;
            }
            j--;
            k++;
        }

    }

    return longest = s.slice(start, end+start);
};

var str1 = 'abcvvcccccccvcdfavxnnjxva';
var res = longestPalindrome(str1);
console.log(res);